-
Notifications
You must be signed in to change notification settings - Fork 603
feat(steering): allow steering on AfterModelCallEvents #1429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(steering): allow steering on AfterModelCallEvents #1429
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| - Interrupt: Pause for human input before tool execution | ||
| """ | ||
|
|
||
| ModelSteeringAction = Annotated[Proceed | Guide, Field(discriminator="type")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is interrupt excluded because we cannot? Is that something that you'll want next?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, I wonder if we should just expose Interrupt now, throw in the case for now, and unlock the ability to do so later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Interrupt until #1165 since we can only interrupt on tool steering. I chose to break symmetry in favor of "compile" time checks rather than a runtime exception or no op.
I think there is uncertainty here. Proceed will always be present since its the no-op case. What I am not confident about is whether or not model and tool steering will diverge.
|
We are failing with "Potential API changes detected (review if actually breaking)" this is true, but we are in experimental so this should not strictly be a blocker. |
🎯 Review - Steering on AfterModelCallEventsThis is an excellent feature that addresses a key limitation in the steering system! The ability to steer after model responses opens up many valuable use cases like quality checks, required tool enforcement, and conversation flow control. What I Really Like ✅
Addressing the CI Failure
|
82ff105 to
aa67698
Compare
Description
Expands the steering system to support model response steering via
AfterModelCallEvent, addressing a key limitation where steering could only influence tool selection and execution.Previously, steering handlers could only intercept tool calls via
steer()(nowsteer_before_tool()). This meant there was no way to:This PR adds
steer_after_model()which is called after each model response, enabling handlers to:A practical example from the issue: ensuring an agent sends a required confirmation message or uses a mandatory tool before completing a workflow. The new
steer_after_model()hook interceptsend_turnresponses and can force retries with guidance until requirements are met.API Changes
New method on
SteeringHandler:New type aliases for type safety:
ToolSteeringAction = Proceed | Guide | Interrupt- forsteer_before_tool()ModelSteeringAction = Proceed | Guide- forsteer_after_model()Renamed with deprecation:
steer()→steer_before_tool()(old method emitsDeprecationWarning)Example: Enforcing Tool Usage
Related Issues
This PR move the needle for #1386.
Type of Change
New feature
Testing
Reorganized
test_tool_steering.pyfor existing tool steering testsUpdated unit tests in
test_handler.pyfor new method signaturesI ran
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.